'use strict'

// 编译后的部署脚本

let copy = require("copy");
copy(["src/*.json", "src/*.js", "src/db/*.json", "src/schdl/*.json", "src/spider/*.json", "src/utils/*.json"], "dist", function (err, files) {
    if (err) return console.error(err);
    files.forEach(function (file) {
        console.log(file.relative);
    })
});
const fs = require('fs');
const path = require('path');

let copyDir = function (src, dest) {
    if (fs.existsSync(src)) {
        const stats = fs.existsSync(src) && fs.statSync(src);
        const isDirectory = fs.existsSync(src) && stats.isDirectory();

        if (fs.existsSync(src) && isDirectory) {
            if (!fs.existsSync(dest))
                fs.mkdirSync(dest);
            fs.readdirSync(src).forEach(function (key) {
                copyDir(path.join(src, key), path.join(dest, key));
            });
        } else {
            try {
                fs.linkSync(src, dest);
            } catch (e) {

            }
        }
        console.log(src + "=>" + dest);
    }
}
copyDir("src/node_modules", "dist/node_modules");
copyDir("src/web", "dist/web");
console.log("compile and deploy successful!!");